<?php

class Course extends Eloquent {
	protected $guarded = array();

	public static $rules = array(
		'course_name' 	=> 'required',
		'course_type'	=> 'required',
		'start_time' 	=> 'required',
		'end_time' 		=> 'required',
		'quantity' 		=> 'required',
		'fee_courses'	=> 'required',
		'post'			=> ''
	);
	public function countquantity($id)
	{
		$results = DB::table('enroll_courses')->where('course_id', '=', $id)->count();
		return $results;
	}

	public function registered($id)
	{
		$results = DB::table('enroll_courses')
					->where('course_id', '=', $id)
					->where('user_id', '=', Auth::user()->id)
					->count();
		return $results;
	}
	public function registered_list()
	{
		$results = DB::table('courses')
					->join('enroll_courses', 'enroll_courses.course_id', '=', 'courses.id')
					->select('enroll_courses.id', 'courses.course_type', 'courses.start_time','courses.end_time')
					->where('enroll_courses.user_id', '=', Auth::user()->id)
					->get();
		return $results;
	}
}
